package com.dhy.canal;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;


/**
 * @author 大忽悠
 * @create 2022/12/27 9:30
 */
@ConfigurationProperties(prefix = "spring.canal")
@Data
public class CanalProperties implements InitializingBean {
    /**
     * 主机地址
     */
   private String host;
    /**
     * 端口号
     */
   private Integer port;
    /**
     * destination
     */
   private String destination;
    /**
     * 当canal没有监听到数据变化时,客户端多久轮询一次数据,单位: 秒
     */
   private Integer fetchInterval=1;
    /**
     * canal客户端一次向canal服务器请求多少条数据
     */
   private Integer fetchSize=100;
    /**
     * 是否开启数据库列属性到java bean属性的下划线转驼峰映射
     */
   private Boolean underlineToCamel=Boolean.TRUE;


    @Override
    public void afterPropertiesSet() throws Exception {
        StringBuilder exBuilder=new StringBuilder();
        if(StringUtils.isEmpty(host)){
            exBuilder.append("canal server host不能为空!  ");
        }
        if(port==null){
           exBuilder.append("canal server port不能为空!");
        }
        if(StringUtils.isEmpty(destination)){
            exBuilder.append("canal server destination不能为空!");
        }
        String exStr = exBuilder.toString();
        if(!StringUtils.isEmpty(exStr)){
            throw new IllegalArgumentException(exStr);
        }
    }
}
